package edu.neu.highway.service.impl;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.WriteApiBlocking;
import com.influxdb.client.domain.WritePrecision;
import edu.neu.highway.service.IFluxImportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <h1>数据导入服务实现类</h1>
 */
@Service
@Slf4j
public class FluxImportServiceImpl implements IFluxImportService {
    private final InfluxDBClient influxDBClient;

    public FluxImportServiceImpl(InfluxDBClient influxDBClient) {
        this.influxDBClient = influxDBClient;
    }

    @Override
    public void fluxImportByLineProtocol(String lineProtocol) {
        WriteApiBlocking writeApi = influxDBClient.getWriteApiBlocking();
        writeApi.writeRecord(WritePrecision.MS, lineProtocol);
    }
}
